1
2
3
4
5
6
7
8
9
10
11
12 package com.aimedia.ui;
13
14 import java.awt.Font;
15
16 import javax.swing.JLabel;
17
18 /***
19 * A go-to class for generic UI components that we seem to spend too much
20 * effort re-implementing. If something needs to be build many times the same
21 * way, it's probably best to put a method to do so in here.
22 *
23 * @author Chris Rose
24 */
25 public class UIPartFactory {
26
27 /***
28 * Not allowed to be instantiated.
29 */
30 private UIPartFactory() {}
31
32 /***
33 * Return a label with the given text, right-aligned.
34 * @param text the text to use on the label.
35 * @return a <code>JLabel</code> object with the supplied text
36 */
37 public static final JLabel createFieldLabel(String text) {
38 return createFieldLabel(text, false);
39 }
40
41 /***
42 * Return a label with the given text, right-aligned.
43 * @param text the text to use on the label.
44 * @param bold <code>true</code> if the label is to have boldface text,
45 * <code>false</code> otherwise.
46 * @return a <code>JLabel</code> object with the supplied text and font hints.
47 */
48 public static final JLabel createFieldLabel(String text, boolean bold) {
49 JLabel label = new JLabel(text, JLabel.RIGHT);
50 if (bold) {
51 label.setFont(label.getFont().deriveFont(Font.BOLD));
52 }
53 return label;
54 }
55 }